package com.unknow.first.dapp.admin.account.utils;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.unknow.first.dapp.admin.account.mapper.FlashSwapPair;
import com.unknow.first.dapp.admin.account.mapper.FlashSwapPairMapper;
import org.cloud.utils.SpringContextUtil;
import org.springframework.context.annotation.Lazy;

public final class FlashSwapUtil {

    private final FlashSwapPairMapper flashSwapPairMapper;

    @Lazy
    private FlashSwapUtil() {
        flashSwapPairMapper = SpringContextUtil.getBean(FlashSwapPairMapper.class);
    }

    public String getPairNameById(final Integer swapPairId) {
        FlashSwapPair flashSwapPair =  flashSwapPairMapper.selectOne(Wrappers.<FlashSwapPair>lambdaQuery().eq(FlashSwapPair::getSwapPairId, swapPairId)
            .select(FlashSwapPair::getCoin1Symbol, FlashSwapPair::getCoin2Symbol));
        if(flashSwapPair==null){
            return null;
        }
        return String.format("%s_%s",flashSwapPair.getCoin1Symbol(), flashSwapPair.getCoin2Symbol());
    }



    private final static FlashSwapUtil flashSwapUtil = new FlashSwapUtil();

    public static FlashSwapUtil single() {
        return flashSwapUtil;
    }

}
